package com.example.carefree_server.controller.c_departmentController;


import com.example.carefree_server.entity.Result;
import com.example.carefree_server.entity.Tweet;
import com.example.carefree_server.service.s_departmentService.ArticleService;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    //发布推文
    @PostMapping("/add")
    private Result addArticle(@RequestBody Tweet t){
        articleService.addArticle(t);
        return Result.success();
    }

    //更新推文
    @PutMapping("/update")
    private Result updateArticle(@RequestBody Tweet t){
        articleService.updateArticle(t);
        return Result.success();
    }

    //删除推文
    @DeleteMapping("/delete")
    private Result deleteArticle(Integer tid){
        articleService.deleteArticle(tid);
        return Result.success();
    }

    //查询所有推文
    @GetMapping("/all")
    private Result selectAll(){
        return Result.success(articleService.selectAll());
    }

    //查询单一指定推文
    @GetMapping("/select")
    private Result select(Integer tid){
        return  Result.success(articleService.select(tid));
    }

    //查询当前部门所有设计过的推文
    @GetMapping("/selectByDid")
    private Result selectByDid(@RequestParam String did){
        return  Result.success(articleService.selectByDid(did));
    }
}
